//
//  NetWorkTool.m
//  ParagonCure
//
//  Created by 牛晴晴 on 16/7/5.
//  Copyright © 2016年 SH. All rights reserved.
//

#import "NetWorkTool.h"

@implementation NetWorkTool
//单例 实例化
+(instancetype)shareManager{

    static NetWorkTool *instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        //1.实例化
        instance = [[NetWorkTool alloc]initWithSessionConfiguration:configuration];
        
        //2.可接受的格式
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
        
        //3.请求格式(默认:二进制)
        instance.requestSerializer = [AFJSONRequestSerializer serializer];
        
        //4.超时
        instance.requestSerializer.timeoutInterval = 10.0;
        
        
    });
    return instance;
}

//自定义的 GET请求
- (void)GET_RequestWithUrlString:(NSString *)urlString parmas:(NSDictionary *)params successBlock:(SuccessCompletedBlock)success failureBlock:(FailureCompletedBlock)failure{

    [[NetWorkTool shareManager] GET_RequestWithUrlString:urlString parmas:params successBlock:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failureBlock:^(NSError *error) {
        
        if (failure) {
            
            failure(error);
        }
    }];
}

//自定义的POST 请求

- (void)POST_RequestWithUrlString:(NSString *)urlString parmas:(NSDictionary *)params successBlock:(SuccessCompletedBlock)success  failureBlock:(FailureCompletedBlock)failure{
    
    [[NetWorkTool shareManager]POST_RequestWithUrlString:urlString parmas:params successBlock:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}
@end
